package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.common.dto.QueryPageBeanDTO;
import com.itheima.common.entity.PageResult;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckItemServiceImpl implements CheckItemService {
    @Autowired
    private CheckItemMapper orderMapper;

    /**
     * 添加检查项
     * @param checkItem
     */
    @Override
    public void addCheckitem(CheckItem checkItem) {
        orderMapper.insertCheckitem(checkItem);
    }

    /**
     * 删除检查项
     * @param id
     */
    @Override
    public void deleteCheckitem(Integer id) {
        orderMapper.deleteCheckitem(id);
    }

    /**
     * 修改检查项
     * @param checkItem
     */
    @Override
    public void modifyCheckitem(CheckItem checkItem) {
        orderMapper.modifyCheckitem(checkItem);
    }

    /**
     * 根据id查询检查项
     * @param id
     * @return
     */
    @Override
    public CheckItem getCheckitemById(Integer id) {
        CheckItem checkItem = orderMapper.getCheckitemById(id);
        return checkItem;
    }

    /**
     * 分页查询检查项
     * @param queryPageBeanDto
     * @return
     */
    @Override
    public PageResult pageCheckitem(QueryPageBeanDTO queryPageBeanDto) {
        PageHelper.startPage(queryPageBeanDto.getPage(),queryPageBeanDto.getPageSize());
        Page<CheckItem> p = orderMapper.pageCheckitem(queryPageBeanDto);
        PageResult pageResult = new PageResult(p.getTotal(),p.getResult());
        return pageResult;
    }

    /**
     * 根据检查项id查询检查项
     * @param id
     * @return
     */
    @Override
    public List<CheckItem> getCheckitemsById(Integer id) {
        return orderMapper.getCheckitemsById(id);
    }
}
